package me.zd.tool.hardlink.view.listener;

import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.function.Consumer;

public class CheckBoxChangedListener implements ItemListener {
    private final JCheckBox component;
    private final Consumer<Boolean> changedOperation;
    private final ModelLock modelLock;

    public CheckBoxChangedListener(JCheckBox component, Consumer<Boolean> changedOperation, ModelLock modelLock) {
        this.component = component;
        this.changedOperation = changedOperation;
        this.modelLock = modelLock;
    }

    @Override
    public void itemStateChanged(ItemEvent e) {
        if (!modelLock.isLocked()) {
            changedOperation.accept(component.isSelected());
        }
    }
}
